/*
 *  $TEAM_NAME Space Trader
 */

package models;

import java.util.Observable;
import javax.swing.BoundedRangeModel;
import javax.swing.event.ChangeListener;

/**
 * The Approach class represents an approach in space trader 
 * from one planet to another
 * @author Bradley Wittenbrook
 * @version 1.0
 */
public final class Approach extends Observable {
	/**
	 * The approach type
	 */
	private ApproachType type;
	
	/**
	 * Which star system is being approached
	 */
	private StarSystem ss;
	
	/**
	 * The distance to the next system
	 */
	private Progress progress;
	
	/**
	 * Which game is being played
	 */
	private Game game;
	
	/**
	 * Constant approach extender
	 */
	public static final int APPROACH_MULTIPLY= 5;
	
	/**
	 * Makes the approach at least length 10
	 */
	public static final int APPROACH_BUILD=10;
	
	/**
	 * Creates a new approach
	 * NOTE: DO NOT DELETE!! Used to save and load
	 */
	public Approach(){
		this.game = null;
	};
	
	/**
	 * Creates a new approach 
	 * @param type
	 * @param ss
	 * @param game
	 */
	public Approach(ApproachType type, StarSystem ss, Game game){
		this.type = type;
		this.ss = ss;
		this.game = game;
		this.progress = new Progress(type.ordinal() * APPROACH_MULTIPLY + APPROACH_BUILD);
	}
	
	/**
	 * Gets the approach type
	 * @return the approach type
	 */
	public ApproachType getType() {
		return type;
	}

	/**
	 * Sets the approach type
	 * @param type - the type of approach
	 */
	public void setType(ApproachType type) {
		this.type = type;
	}

	/**
	 * @return the ss
	 */
	public StarSystem getSs() {
		return ss;
	}

	/**
	 * @return the game
	 */
	public Game getGame() {
		return game;
	}

	/**
	 * @param game the game to set
	 */
	public void setGame(Game game) {
		this.game = game;
	}

	/**
	 * @param ss the ss to set
	 */
	public void setSs(StarSystem ss) {
		this.ss = ss;
	}

	/**
	 * Gets the current progress
	 * @return the type of approach
	 */
	public Progress getProgress() {
		return progress;
	}
	
	/**
	 * Sets the progress
	 * @param progress - the progress
	 */
	public void setProgress(Progress progress) {
		this.progress = progress;
	}

	/**
	 * Represents the various approach type
	 * @author bradley
	 */
	public enum ApproachType{
		SHORT,
		MEDIUM,
		LONG
	}
	
	/**
	 * Goes to next turn
	 */
	public void nextTurn(){
		this.progress.setValue(this.progress.getValue() + 1);
	}
	
	/**
	 * Handles the progress of the approach, or how close
	 * the player is to the destination planet
	 * @author bradley
	 */
	public static class Progress implements BoundedRangeModel{
		/**
		 * The max progress distance
		 */
		private int max;
		
		/**
		 * The minimum progress distance
		 */
		private int min;
		
		/**
		 * Something about progress
		 */
		private int extent;
		
		/**
		 * Probably the current progress. Who knows really.
		 */
		private int value;
		
		/**
		 * Looks for change in the progress
		 */
		@SuppressWarnings("unused")
		private ChangeListener cl;
		
		/**
		 * Indicates wether the progress is currently changing or not
		 */
		private boolean valueIsAdjusting;
		
		/**
		 * Creates a new progress object
		 * @param maxRange
		 */
		public Progress(int maxRange){
			this.setMaximum(maxRange);
			this.setMinimum(0);
		}

		/**
		 * Adds change listener
		 * @param arg0
		 */
		@Override
		public void addChangeListener(ChangeListener arg0) {
			this.cl = arg0;
		}

		/**
		 * Gets the extent
		 * @return the extent
		 */
		@Override
		public int getExtent() {
			return this.extent;
		}

		/**
		 * Gets the max
		 * @return the max
		 */
		@Override
		public int getMaximum() {
			return this.max;
		}

		/**
		 * Gets the min
		 * @return the min
		 */
		@Override
		public int getMinimum() {
			return this.min;
		}

		/**
		 * Gets the value
		 * @return the value
		 */
		@Override
		public int getValue() {
			return this.value;
		}

		/**
		 * Gets the va
		 * @return the if the v is a
		 */
		@Override
		public boolean getValueIsAdjusting() {
			return this.valueIsAdjusting;
		}

		/**
		 * removes the cl
		 * @param arg0
		 */
		@Override
		public void removeChangeListener(ChangeListener arg0) {
			this.cl = null;
			
		}

		/**
		 * Sets the extent
		 * @param arg0
		 */
		@Override
		public void setExtent(int arg0) {
			this.extent = arg0;
			
		}

		/**
		 * Sets the max
		 * @param arg0 the max
		 */
		@Override
		public final void setMaximum(int arg0) {
			this.max = arg0;
			
		}

		/**
		 * Sets the min 
		 * @param arg0 the min
		 */
		@Override
		public final void setMinimum(int arg0) {
			this.min = arg0;
			
		}

		/**
		 * Sets range properties
		 * @param arg0
		 * @param arg1
		 * @param arg2
		 * @param arg3
		 * @param arg4
		 */
		@Override
		public void setRangeProperties(int arg0, int arg1, int arg2, int arg3,
				boolean arg4) {
			this.value = arg0;
			this.extent = arg1;
			this.min = arg2;
			this.max = arg3;
			this.valueIsAdjusting = arg4;
			
		}

		/**
		 * Sets the value
		 * @param arg0
		 */
		@Override
		public void setValue(int arg0) {
			this.value = arg0;
			
		}

		/**
		 * Sets if the v is a
		 * @param arg0
		 */
		@Override
		public void setValueIsAdjusting(boolean arg0) {
			this.valueIsAdjusting = arg0;
			
		}
		
		/**
		 * to string
		 * @return to string
		 */
		@Override
		public String toString() {
			return "";
		}
	}
	
	/**
	 * to string
	 * @return to string
	 */
	public String toString() {
		return "";
	}
}
	

